#ifndef XGE_XFORMAT_H_
#define XGE_XFORMAT_H_
#include "xge_common_config.h"
#include "xallocator.h"


#include <stdarg.h>
namespace xge {
namespace xge_internal {

  // This formatter is thread safe definitely and
  // safe 
  class Format {
  public:
    Format ( const char_t* format , va_list var ) {
      Format( format , var );
    }
    Format( const char_t* format , ... ) {
      va_list list;
      va_start(list,format);
      FormatString(format,list);
    }
    Format():buffer_( NULL ) , size_( 0 ){}
  public:
    // FormatString the string using the heap memory so it may
    // dynamically expand the memory buffer , however , 
    // it also may fail since the formatted string should not
    // be too big to fit into the expected loop times
    bool FormatString( const char_t* format , va_list var );
    bool FormatString( const char_t* format , ... ) {
      va_list list;
      va_start(list,format);
      return FormatString(format,list);
    }
  public:
    const char_t* buffer() const {
      return buffer_;
    }
    size_t size() const {
      return size_;
    }
    ~Format() {
      if( buffer_ ) 
        XFree(buffer_);
    }
  private:
    char_t* buffer_;
    size_t  size_;
    DISALLOW_COPY_AND_ASSIGN(Format);
  };

  int GetAnsiStr2UnicodeBufferSize( const char* in_str );
  int ConvertAnsiStr2Unicode( const char* in_str , wchar_t* out_strbuf , size_t max_size );

}
} // namespace xge
#endif // XGE_XFORMAT_H_